mod bbase64;
mod csv;
mod genpass;
mod text;

use std::path::Path;

use clap::Parser;

pub use bbase64::{Base64Format, Subbase64Command};
pub use csv::{CsvOpts, OutputFormat};
pub use genpass::GenpassOpts;
pub use text::{SubTextCommand, TextSignFormat};

#[derive(Debug, Parser)]
#[command(name = "rcli", version, author = "zhekechen")]
pub struct CmdOpts {
    #[command(subcommand)]
    pub cmd: SubCommand,
}

#[derive(Debug, Parser)]
pub enum SubCommand {
    #[command(name = "csv", about = "Show CSV, or convert CSV to JSON")]
    Csv(CsvOpts),
    #[command(name = "genpass", about = "generate rand passworld")]
    Genpass(GenpassOpts),
    #[command(subcommand, about = "encode file to base64, and decode base64 to file")]
    Base64(Subbase64Command),
    #[command(subcommand, about = "text generate private/shared key and sign/verify")]
    Text(SubTextCommand),
}

fn verify_input_file(filename: &str) -> Result<String, &'static str> {
    // if input is "-" or file exists
    if filename == "-" || Path::new(filename).exists() {
        Ok(filename.into())
    } else {
        Err("File does not exist")
    }
}
